package com.yimi.yinhepda.views.sign_manager

import com.pda.ym.callbacks.UICallBack
import com.pda.ym.net.NetRequest
import com.pda.ym.utils.Constants
import com.yimi.yinhepda.entity.response.QueryBaseDictResponse
import com.yimi.yinhepda.utils.Common
import com.yimi.yinhepda.utils.ToastUtil
import java.util.*

/**
 * @author: lj
 * Date: 2020/7/22 15:33
 * Description:
 */
object BreakCardUtil {

    /**
     * 打卡开关，默认1-旧功能,0-新功能
     */
    @JvmStatic
    fun queryBreakCardSwitch() {
        val params: MutableMap<String, String> = HashMap(2)
        params["dictCode"] = "vms_car_clock_switch"
        //查询类型，1-只查询未作废的，为null则查询所有(包含作废和未作废的)
        params["type"] = "1"

        NetRequest().setMethod(NetRequest.Method.GET)
                .setResponsClazz(QueryBaseDictResponse::class.java)
                .setUrl(Constants.URL_QUERY_DICT)
                .setParams(params)
                .execute(object : UICallBack() {
                    override fun onError(msg: String) {
                        ToastUtil.showToast(msg)
                    }

                    override fun onSuccess(obj: Any) {
                        val response = obj as QueryBaseDictResponse?
                        if (response?.data != null) {
                            val dictlist = response.data
                            if (dictlist != null && dictlist.isNotEmpty()) {
                                val entity = dictlist[0]
                                try {
                                    Common.BREAK_CARD_SWITCH = entity.dictValue.toInt()
                                } catch (e: NumberFormatException) {
                                    e.printStackTrace()
                                }
                            }
                        }
                    }
                })
    }
}